﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace DARE
{
    [AttrTypeDependentSerializable(typeof(DARE.Save.DataStructures.CSkyPlaneData))]
    class CSkyPlane: ASky
    {

        #region ctor
           
        private void ctor()
        {
            m_effect = CResourceMgr.Load<Effect>("Shaders/Skies");// IDEEEEEM
            m_technique = "PlaneMapping";
        }

        public CSkyPlane(CRender3D render3D, string planeMapName)
            : base(render3D)
        {
            m_texture = CResourceMgr.Load<Texture2D>(planeMapName);
            ctor();
        }

        public CSkyPlane(CRender3D render3D, Texture2D planeMap)
            :base(render3D)
        {
            m_texture = planeMap;
            ctor();
        }

        #endregion

        #region methods

        protected override void CreateModel(out Microsoft.Xna.Framework.Graphics.VertexBuffer vb, out Microsoft.Xna.Framework.Graphics.IndexBuffer ib)
        {
            VertexPositionColor[] vertices = new VertexPositionColor[4]
                {
                    new VertexPositionColor(new Vector3(-1f, 1f, -1f), Color.White),
                    new VertexPositionColor(new Vector3(1f, 1f, -1f), Color.White),
                    new VertexPositionColor(new Vector3(-1f, 1f, 1f), Color.White),
                    new VertexPositionColor(new Vector3(1f, 1f, 1f), Color.White)
                };
            vb = new VertexBuffer(CDare.Instance.GraphicsDevice, typeof(VertexPositionColor), vertices.Length, BufferUsage.None);
            vb.SetData<VertexPositionColor>(vertices);

            short[] indices = new short[6]
            { 0, 1, 3, 0, 3, 2 };
            ib = new IndexBuffer(CDare.Instance.GraphicsDevice, IndexElementSize.SixteenBits, indices.Length, BufferUsage.None);
            ib.SetData<short>(indices);
        }

        #endregion

    }
}
